/***********************************************************
 
 File name: AATabbarVC.m
 Author:    xuwei
 Description:
 tabbar管理类
 
 2018/02/27: Created
 
 ************************************************************/

#import "AATabbarVC.h"
#import "AAHomeVC.h"
#import "AAOrderVC.h"
#import "AAMineVC.h"

@interface AATabbarVC ()
/** homeVC */
@property (nonatomic, strong) AAHomeVC *homeVC;
/** orderVC */
@property (nonatomic, strong) AAOrderVC *orderVC;
/** mineVC */
@property (nonatomic, strong) AAMineVC *mineVC;
@end

@implementation AATabbarVC
#pragma mark - Life Circle 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupViewControllers];
}

#pragma mark - Public Method 公开方法（头文件声明的方法）
#pragma mark - System Delegate Method 系统自带的代理方法
#pragma mark - System DataSource Method 系统自带的数据源方法
#pragma mark - Custom Delegate Method 自定义的代理方法
#pragma mark - Event Response Method 事件响应方法
#pragma mark - Private Method 私有方法
/**
 配置tabbar对应的vc的属性

 @param viewController vc
 @param title 标题
 @param imageName 图片
 @param selectImage 选中图片
 @param index 选中下标
 */
- (void)setupViewController:(UIViewController *)viewController
                      title:(NSString *)title
                      image:(NSString *)imageName
              selectedImage:(NSString *)selectImage
                        tag:(AATabbarIndex)index {
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // 取消系统渲染
    viewController.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [viewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:kNavigationColor],NSFontAttributeName: [UIFont systemFontOfSize:kTextFontSize12]} forState:UIControlStateNormal];
//    [viewController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:kUltramarineColor]} forState:UIControlStateSelected];
    
    viewController.tabBarItem.tag = index;
}

/**
 配置vc
 */
- (void)setupViewControllers {
    // 主页
    AANavigationVC *homeNav = [[AANavigationVC alloc] initWithRootViewController:self.homeVC];
    [self setupViewController:homeNav title:@"首页" image:@"tabbar_home_normal" selectedImage:@"tabbar_home_selected" tag:AATabbarIndex_Home];
    
    // 订单
    AANavigationVC *orderNav = [[AANavigationVC alloc] initWithRootViewController:self.orderVC];
    [self setupViewController:orderNav title:@"订单" image:@"tabbar_order_normal" selectedImage:@"tabbar_order_selected" tag:AATabbarIndex_Order];
    
    // 我的
    AANavigationVC *mineNav = [[AANavigationVC alloc] initWithRootViewController:self.mineVC];
    [self setupViewController:mineNav title:@"我" image:@"tabbar_mine_normal" selectedImage:@"tabbar_mine_selected" tag:AATabbarIndex_Mine];
    
    self.viewControllers = @[homeNav, orderNav, mineNav];
}

#pragma mark - Getters and Setters Method getter和setter方法
- (AAHomeVC *)homeVC {
    if (!_homeVC) {
        AAHomeVC *homeVC = [[AAHomeVC alloc] init];
        _homeVC = homeVC;
    }
    return _homeVC;
}

- (AAOrderVC *)orderVC {
    if (!_orderVC) {
        AAOrderVC *orderVC = [[AAOrderVC alloc] init];
        _orderVC = orderVC;
    }
    return _orderVC;
}

- (AAMineVC *)mineVC {
    if (!_mineVC) {
        AAMineVC *mineVC = [[AAMineVC alloc] init];
        _mineVC = mineVC;
    }
    return _mineVC;
}
@end
